Ext.define('AkData.view.Login', {
    extend: 'Ext.form.Panel',
    alias: "widget.loginview",
    requires: ['Ext.form.FieldSet', 'Ext.form.Password', 'Ext.Label', 'Ext.Img', 'Ext.util.DelayedTask'],
    config: {
        title: _lang_Giris,
		//standardSubmit: true,
		/*
		onSubmit: function(e) {
			e.stopEvent();
			var me = this;
			me.onLogInButtonTap();
			//return false;
		},
		*/
		control:{
            'fieldset[name=login-form]':{
                action: 'onLogInButtonTap'
            }
        },
		
        items: [
			/*
            {
                xtype: 'image',
                src: Ext.Viewport.getOrientation() == 'portrait' ? 'akdatalogo80x80.png' : 'akdatalogo40x40.png',
                style: Ext.Viewport.getOrientation() == 'portrait' ? 'width:80px;height:80px;margin:auto' : 'width:40px;height:40px;margin:auto'
            },
			*/
			{
				xtype: 'titlebar',
				docked: 'top',
				title: 'akdatasoft',
			},
            {
                xtype: 'label',
                html: _lang_Girisbasarisiz,
                itemId: 'signInFailedLabel',
                hidden: true,
                hideAnimation: 'fadeOut',
                showAnimation: 'fadeIn',
                style: 'color:#990000;margin:5px 0px;'
            },
            {
                xtype: 'fieldset',
                //title: _lang_Lutfenbilgilerinizigiriniz,
				itemId: 'login-form',
				name: 'login-form',
                items: [
					{
                        xtype: 'selectfield',
                        name: 'languageTextField',
						itemId: 'languageTextField',
                        label: 'Dil',
                        //valueField: 'value',
                        //displayField: 'display',
						defaultPhonePickerConfig : {
							doneButton : 'Tamam',
							cancelButton : 'İptal'
						},
						options: [
							{text: 'Türkçe',  value: 'tr'},
							{text: 'İngilizce', value: 'en'},
						],
                    },
                    {
                        xtype: 'textfield',
                        placeHolder: _lang_Kullaniciadi,
                        itemId: 'userNameTextField',
                        name: 'userNameTextField',
                        required: true,
						autoComplete: false,
						autoCorrect: false,
                    },
                    {
                        xtype: 'passwordfield',
                        placeHolder: _lang_Sifre,
                        itemId: 'passwordTextField',
                        name: 'passwordTextField',
                        required: true
                    }
                ]
            },
            {
                xtype: 'button',
                itemId: 'logInButton',
                ui: 'action',
                margin: '10px',
                text: _lang_Giris,
				//style: 'background: gray',
            }
        ],
        listeners: [
			{
				delegate: '#logInButton',
				event: 'tap',
				fn: 'onLogInButtonTap'
			}
		]
    },
    onLogInButtonTap: function () {

        var me = this,
            usernameField = me.down('#userNameTextField'),
            passwordField = me.down('#passwordTextField'),
			languageField = me.down('#languageTextField'),
			
            label = me.down('#signInFailedLabel'),
            username = usernameField.getValue(),
            password = passwordField.getValue(),
			language = languageField.getValue();

        label.hide();

        // Using a delayed task in order to give the hide animation above
        // time to finish before executing the next steps.
        var task = Ext.create('Ext.util.DelayedTask', function () {

            label.setHtml('');

            me.fireEvent('signInCommand', me, username, password, language);

            usernameField.setValue('');
            passwordField.setValue('');
        });

        task.delay(500);

    },
    showSignInFailedMessage: function (message) {
        var label = this.down('#signInFailedLabel');
        label.setHtml(message);
        label.show();
    }
});